<?php
set_time_limit(0); 
// error_reporting(0);
define('PATH', substr(dirname(__FILE__),0,-13));

$cfg_config = include PATH . '/config/config.php';
include PATH . '/core/mysql_db.php';
include PATH . '/core/pinyin.class.php';
$mysql_config = $cfg_config['mysql'];
$db = new MYSQL($mysql_config);

$file_name =PATH. "/config/keys.txt";
if(!file_exists($file_name)){
	die("File Not Found ({$file_name})");
}
$fp = fopen($file_name, 'r');
$space = array("\r\n", "\n", "\r");
$x = 0;
while (!feof($fp)) {
    $buffer = fgets($fp, 4096);
	$buffer = str_replace("'", "\'", $buffer);
	$buffer = str_replace($space, '', $buffer);

	$key = $buffer ;
	$py = @pinyin :: encode($key);
	$py = trim($py);
	if (trim($key) == '' || $py =='') {
		continue;
	} //自动跳过空行 和无法识别的拼音
    $sql = "INSERT IGNORE  INTO `video_keys` (`key`,`py`) VALUES ('{$key}','{$py}');";
    $num = $db -> execute($sql);
	if($num==0){
		$py .= rand(0,999);
		$sql = "INSERT IGNORE  INTO `video_keys` (`key`,`py`) VALUES ('{$key}','{$py}');";
		$db -> execute($sql);
	}
	
	echo "\r" . $x++ . ':---------> OK!';
} 
echo "\n Over ... \n";
$db -> close();

?>
